package com.sixmac.platform.service.impl;

import com.sixmac.core.base.service.BaseService;
import com.sixmac.core.constant.ConstCache;
import com.sixmac.core.constant.ConstCacheKey;
import com.sixmac.core.toolbox.ajax.AjaxResult;
import com.sixmac.core.toolbox.cache.CacheKit;
import com.sixmac.module.Installer;
import com.sixmac.platform.service.LoginService;
import org.springframework.stereotype.Service;

import java.util.UUID;

/**
 * Created by admin on 2018/9/5.
 */
@Service
public class LoginServiceImpl extends BaseService<Installer> implements LoginService {


    public AjaxResult login(String account, String password) {
        Installer installer = this.findFirstBy("account=#{account}", getData("account", account));
        if (installer == null)
            return error("账号不存在");
        if (!installer.getPassword().equals(password))
            return error("密码错误");

        String token = UUID.randomUUID().toString();
        CacheKit.put(ConstCache.SYS_USER + ConstCacheKey.USER_AUTH_TOKEN, token, installer);
        installer.setToken(token);
        return AjaxResult.initAjaxResult().setData(getData("installer", installer));
    }

}
